<template>
  <div class="HomeAlbum w">
    <div v-if="newAlbumList.length === 0 && allAlbumList.length === 0">
      <el-skeleton animated :throttle="500" style="height: 400px">
        <template slot="template">
          <el-skeleton-item
            variant="image"
            style="height: 300px; width: 100%"
          />
          <el-skeleton-item
            variant="p"
            style="height: 30px; width: 100%; margin-top: 8px"
          />
        </template>
      </el-skeleton>
    </div>
    <div v-else>
      <div class="title">热门新碟</div>
      <!-- 内容 -->
      <div class="content">
        <div
          class="content_item"
          v-for="item in newAlbumList"
          :key="item.id"
          @click="toAlbumDetailsPage(item.id)"
        >
          <div class="content_item_img">
            <GlobalImageDeep
              :url="item.picUrl"
              :imgWidth="224"
              :imgHeight="224"
            />
            <!-- 播放按钮 -->
            <GlobalPlayMask :maskWidth="64" :maskHeight="64" />
          </div>
          <p class="one_txt_cut">{{ item.name }}</p>
          <i class="one_txt_cut"> {{ formatAuthor(item.artists) }}</i>
        </div>
      </div>
      <div class="title">全部新碟</div>
      <div class="content">
        <div class="content_item" v-for="item in allAlbumList" :key="item.id">
          <div class="content_item_img">
            <GlobalImageDeep
              :url="item.picUrl"
              :imgWidth="224"
              :imgHeight="224"
            />
            <!-- 播放按钮 -->
            <GlobalPlayMask
              :maskWidth="64"
              :maskHeight="64"
              @maskClick="toAlbumDetailsPage(item.id)"
            />
          </div>
          <p class="one_txt_cut">{{ item.name }}</p>
          <i class="one_txt_cut"> {{ formatAuthor(item.artists) }}</i>
        </div>
      </div>
      <!-- 分页 -->
      <el-row type="flex" class="row-bg" justify="center">
        <el-pagination
          layout="prev, pager, next"
          :total="total"
          :page-size="12"
          @current-change="paginationCurrentChange"
          :current-page="currentPage"
        >
        </el-pagination>
      </el-row>
    </div>
  </div>
</template>

<script>
// 新碟上架  页面
import { getNewsAlbum, getAllAlbum } from "../../../../api/xindieApi";
export default {
  name: "HomeAlbum",
  data() {
    return {
      newAlbumList: [],
      allAlbumList: [],
      queryInfo: {
        limit: 12,
        offset: 0,
        area: "ALL",
      },
      total: 0,
      currentPage: 1,
    };
  },
  created() {
    this.getNewsAlbum();
    this.getAllAlbum();
  },
  methods: {
    async getNewsAlbum() {
      try {
        const result = await getNewsAlbum();
        if (result.code === 200) {
          // console.log(result);
          this.newAlbumList = result.albums.slice(0, 8);
          console.log(this.newAlbumList);
        }
      } catch (error) {}
    },
    async getAllAlbum() {
      try {
        const result = await getAllAlbum(this.queryInfo);
        if (result.code === 200) {
          // console.log(result);
          this.allAlbumList = result.albums;
          this.total = result.total;
          console.log(this.allAlbumList);
        }
      } catch (error) {}
    },
    // 切换页码
    paginationCurrentChange(newPage) {
      this.list = [];
      this.currentPage = newPage;
      this.queryInfo.offset = (newPage - 1) * this.queryInfo.limit;
      this.getAllAlbum();
    },
    formatAuthor(artists) {
      let authors = "";
      artists.forEach((item) => {
        authors = authors + item.name + " / ";
        // console.log(authors);
      });
      return authors.slice(0, authors.length - 2);
    },
    toAlbumDetailsPage(id) {
      this.$router.push(`/albumDetails/${id}`);
    },
  },
};
</script>

<style lang="less" scoped>
/deep/ .el-pager li.active {
  color: #fff;
  background: @globalColor;
  border-radius: 50%;
  &:hover {
    color: #fff;
  }
}
/deep/ .el-pager li:hover {
  color: @globalColor;
}
/deep/ .el-image img {
  border-radius: 8px;
}
.HomeAlbum {
  padding: 30px 0;
  color: #000000;
  font-size: 16px;
  .title {
    font-size: 24px;
    padding-bottom: 10px;
    border-bottom: 2px solid @globalColor;
  }
  .content {
    padding: 15px 0;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    .content_item {
      height: 316px;
      width: 288px;
      font-size: 14px;

      &:hover {
        /deep/ .playMask .play {
          display: block;
          cursor: pointer;
        }
      }

      .content_item_img {
        position: relative;
        width: 224px;
        height: 224px;
        &::before {
          content: "";
          position: absolute;
          top: 0;
          left: 30px;
          width: 100%;
          height: 100%;
          background: url("../../../../assets/images/album-cover.png") no-repeat
            center;
        }
      }
      p {
        width: 224px;
        color: #333333;
        margin-top: 10px;
        margin-bottom: 10px;
        &:hover {
          color: @globalColor;
          animation: bounce 1s;
          cursor: pointer;
        }
      }
      i {
        width: 224px;
        display: block;
        color: #999999;
        &:hover {
          color: @globalColor;
          // animation: bounce 1s;
          cursor: pointer;
        }
      }
    }
  }
}
</style>
